﻿using HCQ2_Model.VR.Params;
using HCQ2_Model.VRDD.InputDto;
using HCQ2_Model.VRDD.InputDto._0525;
using HCQ2_Model.VRDD.OutputDto._0525;
using HCQ2_Model.VRDD.OutputDto._0730;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRDDCircleDynamicBLL
    {
        /// <summary>
        ///  动态服务接口
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputDynamicResult> GetDynamicList(InputDynamicList param)
        {
            List<OutputDynamicResult> result = new List<OutputDynamicResult>();
            List<OutputDynamicList> list = DBSession.IT_VRDDCircleDynamicDAL.GetDynamicList(param);
            list?.ForEach(s =>
            {
                OutputDynamicResult temp = new OutputDynamicResult
                {
                    dy_id = s.dy_id,
                    user_id = s.user_id,
                    user_name = s.user_name,
                    du_name = s.du_name,
                    d_note = s.d_note,
                    create_date = s.create_date,
                    gps_x = s.gps_x,
                    gps_y = s.gps_y,
                    create_url = s.create_url,
                    star_status = s.star_status,
                    read_status = s.read_status,
                    video = s.video,
                    user_img = s.user_img,
                    hide_name = s.hide_name,
                    du_friend = s.du_friend
                };
                if (!string.IsNullOrEmpty(temp.video))
                    temp.video = temp.video.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //用户头像地址
                if(!string.IsNullOrEmpty(temp.user_img) && temp.user_img.IndexOf("http")<0)
                    temp.user_img= temp.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //是否清空真实姓名
                if ((s.hide_name == 0 && s.du_friend > 0) || (s.hide_name == 1 && s.du_friend > 1))
                    temp.du_name = string.Empty;
                //图片列表
                var picture = DBSession.IT_VRDDCirclePicListDAL.Select(o => o.du_id == s.user_id && o.d_id == s.dy_id);
                List<CirclePicList> pic = new List<CirclePicList>();
                picture?.ForEach(n => pic.Add(new CirclePicList { img_name = n.img_name, img_url = n.img_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) }));
                temp.picture = pic;
                //用户点赞列表
                var star= DBSession.IT_VRDDCircleDynamicDAL.GetDynamicStar(s.dy_id);
                star?.ForEach(n =>
                {
                    if(!string.IsNullOrEmpty(n.user_img) && n.user_img.IndexOf("http")<0)
                        n.user_img = n.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                });
                temp.userStar = star;
                //用户评论列表
                var review= DBSession.IT_VRDDCircleDynamicDAL.GetDynamicReview(s.dy_id);
                review?.ForEach(n =>
                {
                    if (!string.IsNullOrEmpty(n.user_img) && n.user_img.IndexOf("http")<0)
                        n.user_img = n.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                });
                temp.userReview = review;
                result.Add(temp);
            });
            return result;
        }
        /// <summary>
        ///  获取未读的点赞及评论列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputUnreadDynamicList> GetUnreadDynamicList(DDBaseUser param)
        {
            return DBSession.IT_VRDDCircleDynamicDAL.GetUnreadDynamicList(param);
        }
        /// <summary>
        ///  获取人脉关系
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputRelationShip> GetRelationship(InputRelationShip param)
        {
            List<OutputRelationShip> list = DBSession.IT_VRDDCircleDynamicDAL.GetRelationship(param);
            if (list == null || list.Count <= 2)
                return null;
            list?.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s.user_img) && s.user_img.IndexOf("http")<0)
                    s.user_img = s.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取我的图片动态列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputMyDynamic> GetMyPicDynamic(BaseEParam param, int user_id)
        {
            var list = DBSession.IT_VRDDCircleDynamicDAL.GetMyPicDynamic(param, user_id);
            list?.ForEach(s=> {
                if (!string.IsNullOrEmpty(s.img_url))
                    s.img_url = s.img_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
    }
}